package CommonGui;



import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.font.TextAttribute;
import java.util.HashMap;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

public class ChkRender  implements ListCellRenderer {

	private Dimension screenSize;
	private int x;
	private int y;
	
    @Override
    public Component getListCellRendererComponent(JList arg0, Object obj,int ind, boolean isSelected, boolean cellHasFocus) 
    {

      
    	screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		x=screenSize.width;
		y=screenSize.height;
        String type=((ChkObj) obj).getType();
        
        if(type.equals("checkBox"))
        { 
        //	String text = "<html>First Line<br>Second Line</html>";
        	String text="<html>";
        	text=text+"<br>";
        	text=text+((ChkObj) obj).getTxt();
        	
        	if(((ChkObj) obj).getRecipeActionLevel()!=null)
        		text=text+"<br>"+((ChkObj) obj).getRecipeActionLevel();
        	
        	if(((ChkObj) obj).getRecipeExtra()!=null)
        		text=text+"<br>"+((ChkObj) obj).getRecipeExtra();
        	
        	if(((ChkObj) obj).getRecipeSouce()!=null)
        		text=text+"<br>"+((ChkObj) obj).getRecipeSouce();
        	
        	if(((ChkObj) obj).getRecipeComments()!=null)
        		text=text+"<br>"+((ChkObj) obj).getRecipeComments();
        	
        	text=text+"<br>"+"</html>";
        	
            JTextArea  temp=new JTextArea("temp ");
            JCheckBox checkBox=new JCheckBox(text);
          //  JCheckBox multiLineJCheckBox = new JCheckBox("<font face="\"Arial\"" size="\"3\></font>"JCheckBox with <br> multiline text");
        	///////////////////////////////JCheckBox checkBox=new JCheckBox(((ChkObj) obj).getTxt() + "<br>"+((ChkObj) obj).getRecipeActionLevel());
        	//checkBox.setBorder(new EmptyBorder(50,10, 10, 10));
        	checkBox.setFont((new Font("Tahoma", Font.ITALIC,x/115)));
        	//checkBox.setBorder(new LineBorder(Color.darkGray, 1));
        	checkBox.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.lightGray));

        	checkBox.setBorderPainted(true);
        	checkBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        	
        	Icon normal = new ImageIcon("checkbox-icon.png");
        	
			
        	Icon selected = new ImageIcon("checkbox_selected-icon.png");
        	
        	
        	checkBox.setIcon(normal);
        	checkBox.setSelectedIcon(selected);
        	
        	checkBox.putClientProperty("JComponent.sizeVariant", "10");
        	checkBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        	checkBox.setHorizontalTextPosition(SwingConstants.LEFT);
        	
        	if(!((ChkObj) obj).flagSubmitted)  // esli mana vishla s mitbaha , nelza bolshe stavit V
        	{
        	checkBox.setEnabled(false);
        	checkBox.setSelected(true);
        	}
        	
        	else
        	{
        	
        	checkBox.setSelected(((ChkObj) obj).flagFired);
        	
        	if (isSelected) 
            {
                if (cellHasFocus) {
                	checkBox.setBackground(Color.CYAN);
                } else {
                	checkBox.setBackground(Color.RED);
                }
            } else {
                if (cellHasFocus) {
                	checkBox.setBackground(Color.GREEN);
                } else {
                	checkBox.setBackground(Color.WHITE);
                }
            }
        	}
        	return checkBox;
        }

        
        else 
        {
        	JLabel label=new JLabel();
        	label.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);     	
        	String txt=obj.toString();   	
        	label.setText(txt);
        	      	
        	Map<TextAttribute, Integer> fontAttributes = new HashMap<TextAttribute, Integer>();
        	fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        //	label.setFont((new Font("Tahoma", Font.PLAIN, x/80).deriveFont(fontAttributes)));
        	label.setFont((new Font("Tahoma", Font.PLAIN, x/80)));
        	label.setBorder(BorderFactory.createMatteBorder(8, 0, 0, 0, Color.gray));
        	
        	return label;
        }
       // return null;
    }
}